<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymleaf.org">
<head>
    <meta charset="UTF-8">
    <title>借床</title>
    <script src="../webapp/BootStrap/js/jquery.js"></script>
    <script src="../webapp/BootStrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="../webapp/BootStrap/css/bootstrap.css">
    <link rel="stylesheet" href="../webapp/static/css/login.css">
    <script src="../webapp/static/js/ZhengZe.js"></script>
    <script src="../webapp/static/layui/layui.js"></script>
    <link rel="stylesheet" href="../webapp/static/layui/css/layui.css">

</head>
<style>
    #father{
        width: 600px;
        height: 600px;
        border-radius: 50px;
        background-color:  #6495ED;
        border: #6495ED  5px solid;
        margin:10px auto;
        padding: 15px 15px 0px 15px;
    }
    .chose{
        padding-left: 15%;
        padding-right: 20%;
        padding-top: 2.5%;
        width: 100%;
        height: 10%;
       background-color: white;
        margin-bottom: 10px;
        color: #0C0C0C;
        font-size: 130%;
        line-height: 150%;
    }
    .xinxi{
        padding-left: 15%;
        padding-right: 20%;
        padding-top: 2.5%;
        width: 100%;
        height: 35%;
        background-color: white;
        margin-bottom: 10px;
        color: #0C0C0C;
        font-size: 130%;
        line-height: 150%;
    }
    .sel1{
        float: right;
        padding-top: 0.5%;
    }
    .text1{
        float: left;
    }
    .zi{
        float: left;
        width: 40%;
    }
    .bl{
        float: left;
        width: 40%;
    }
    .xiadan{
        background-color: green;
        color: white;
        border-radius: 5px;
        border: 0px;
        width: 50%;
        height: 100%;
    }
    .xd{
        background-color: mediumvioletred;
        color: white;
        border-radius: 5px;
        border: 0px;
        width: 50%;
        height: 100%;
    }

</style>
<script>
    yiyuan();
    function yiyuan(){
        $.ajax({
            url:"/userorder/findbed",
            type:"post",
            datatype:"json",
            success:function(data){
                var html="";

                for(var i in data.yiyuan){
                    var h = data.yiyuan[i];

                    html+=  "<option value='"+h.hospitalinfoid+"'>"+h.hospitalinfoname+"</option>"

                }
                $("#yi").html(html);
            }
        })
    }

    function huankeshi(){
        var id= $("#yi").val();
        $.ajax({
            url:"/bed/findbyid",
            type:"post",
            datatype:"json",
            data:{"hospitalinfoid":id},
            success:function(data){
                var html="";

                for(var i in data.keShi){
                    var h = data.keShi[i];

                    html+=  "<option value='"+h.departmentid+"'>"+h.departmentname+"</option>"

                }
                $("#ke").html(html);
            }
        })

    }

    function chuang(){
        var yi= $("#yi").val();
        var ke= $("#ke").val();
        $.ajax({
            url:"/userorder/findbed",
            type:"post",
            datatype:"json",
            data:{"hospitalinfoid":yi,"departmentid":ke},
            success:function(data){
                var html="";

                for(var i in data.bed){
                    var c = data.bed[i];
                    html+=  "<option value='"+c.sesBedType.bedtypeid+"'>"+c.sesBedType.bedtypeid+"</option>"
                }
                $("#chuang").html(html);
            }
        })
    }

    function chuangxx(){
        var yi= $("#yi").val();
        var ke= $("#ke").val();
        var chuang=$("#chuang").val();
        $.ajax({
            url:"/userorder/findbed",
            type:"post",
            datatype:"json",
            data:{"hospitalinfoid":yi,"departmentid":ke},
            success:function(data){
                for(var i in data.bed){
                    var c = data.bed[i];
                    if(c.sesBedType.bedtypeid==chuang){
                        $("#bh").html(c.sesBedType.bedtypecode);
                        $("#kc").html(c.sesBedType.bedtypeinventory);
                        $("#dj").html(c.sesBedType.bedtypeprice);
                        $("#hd").val(c.bedmessageid);
                    }
                }
            }
        })
    }
    function tijiao(){
        var money=$("#zj").html();
        var tian =$("#tian").val();
        var bedtypePrice = $("#dj").html();
        var bedmessageId =$("#hd").val();
        var bedtypeInventory=$("#kc").html();

        //alert("bedtypePrice:"+bedtypePrice+"||bedmessageId:"+bedmessageId+"||bedtypeInventory:"+bedtypeInventory)
        $.ajax({
            url:"/userorder/byorder",
            type:"post",
            datatype:"json",
            data:{"bedtypePrice":bedtypePrice,"bedmessageId":bedmessageId,"bedtypeInventory":bedtypeInventory,"money":money,"tian":tian},
            success:function(data){
                if(data.userorderid!=undefined){
                    alert(data.s);
                    var html ="<input type='button' value='确认购买' class='xiadan' onclick='dingdan()'>"+
                        "<input type='hidden' id='uod' value='"+data.userorderid+"'>"
                      $("#anniu").html(html);

                }else{
                    alert(data.s);
                }
            }
        })
    }
    function dingdan(){
        var bedmessageId =$("#hd").val();
        var userorderid =$("#uod").val();
        var money=$("#zj").html();
        var tian =$("#tian").val();
      //alert("bedmessageId"+bedmessageId+"||money:"+money+"||tian:"+tian)
        $.ajax({
            url: "/userorder/updateYuE",
            type: "post",
            datatype: "json",
            data: {"tian": tian, "bedmessageId": bedmessageId, "money": money,"userorderId":userorderid},
            success: function (data) {
             if(data){
                 alert("操作成功！")
                 window.location.href="UserMoney.html"
             }
            }
        })
    }


    function qian(){
        var dj= $("#dj").html();
        var t=$("#tian").val();

        var zong=parseInt(dj) * parseInt(t)
        $("#zj").html(zong)

    }
</script>

<body scroll="no">
    <div id="father">
        <div class="chose">
            <input type="hidden" id="hd"/>
            <div class="text1">选择医院</div>
            <div class="sel1">
                <select id="yi" class="sel1" onclick="huankeshi()">
                    <option>-请选择医院-</option>
                </select>
            </div>
        </div>
        <div class="chose">
            <div class="text1">选择科室</div>
            <div class="sel1">
                <select id="ke" class="sel1" onclick="chuang()">
                    <option>-请选择科室-</option>
                </select>
            </div>
        </div>
        <div class="chose">
            <div class="text1">床</div>
            <div class="sel1">
                <select id="chuang" class="sel1" onclick="chuangxx()">
                    <option>-请选择床位-</option>
                </select>
            </div>
        </div>
        <div class="chose">
            <div class="text1">选择天数</div>
            <div class="sel1">
                <select id="tian" class="sel1"onclick="qian()">
                    <option value="1">1天</option>
                    <option value="2">2天</option>
                    <option value="3">3天</option>
                    <option value="4">4天</option>
                    <option value="5">5天</option>
                </select>
            </div>
        </div>
        <div class="xinxi">
            <div>
                <div id="chuangxinxi">
                  <div class="zi">床位编号:</div>
                    <div id="bh" class="bl">

                </div>
                    <div class="zi">库存:</div>
                    <div id="kc" class="bl">

                </div>
                    <div class="zi">单价:</div>
                    <div id="dj" class="bl">

                </div>
                    <div class="zi">总价:</div>
                    <div id="zj" class="bl">

                    </div>

                </div>
            </div>

        </div>
        <div class="chose">
            <div id="anniu" style="padding-left: 35%">
                <input type="button" value="下单" onclick="tijiao()" class="xd"/>
<!--                <input type="button" value="返回" class="fh" onclick="fan()"/>-->
            </div>
        </div>


    </div>
</body>
</html>
<script>
    $(document.body).css({
        "overflow-x":"hidden",
        "overflow-y":"hidden"
    });

   function fan(){
       window.location.href="/user/UserMoney.html";
    }
</script>
